$(function () {
    //采购方公司加载
    $("#shmx_gs_id").ssgsjgcombotree()
    //合作方加载
    $("#shmx_gys_id").qyjgzcombobox();
    //客户加载
    $("#shmx_kh_id").qyjgzcombobox();

    $("#grid_shmx").datagrid({
        url: $.webPath() + "/xsgl/xsmx/shmxList",
        toolbar: "#toolbar_shmx",
        fitColumns: false,
        singleSelect: true,
        fit: true,
        pageNumber: 1,
        striped: true,
        pagination: true,
        rownumbers: true,
        showFooter: true,
        frozenColumns: [
            [
                {field: 'wly', title: '公司名称', align: 'center', width: 110},
                {field: 'gys', title: '供应商', align: 'center', width: 110},
                {field: 'cght', title: '采购合同', align: 'center', width: 110},
                {field: 'kh', title: '客户', align: 'center', width: 110}
            ]
        ],
        columns: [
            [
                {field: 'xsdh', title: '销售单号', align: 'center', width: 100},
                {field: 'gg.code', title: '物资编码', align: 'center', width: 100},
                {field: 'gg.name', title: '物资名称', align: 'center', width: 100},
                {field: 'ggxh', title: '规格型号', align: 'center', width: 100},
                {field: 'shrq', title: '赎货日期', align: 'center', width: 100},
                {field: 'hsj', title: '赎货价', align: 'center', width: 100, formatter: function (value) {
                    var val = formatSlForHtml(value);
                    return val;
                }},
                {field: 'sl', title: '赎货量', align: 'center', width: 100, formatter: function (value) {
                    var val = formatSlForHtml(value);
                    return val;
                }},
                {field: 'she', title: '赎货额', width: 150, align: 'right', formatter: function (value) {
                    var val = formatJeForHtml2(value);
                    return val;
                }},
                {field: 'yhjg', title: '优惠价', align: 'right', width: 150, formatter: function (value) {
                    var val = formatSlForHtml(value);
                    return val;
                }},
                {field: 'yhe', title: '优惠额', width: 150, align: 'right', formatter: function (value) {
                    var val = formatJeForHtml2(value);
                    return val;
                }}
            ]
        ],
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    });

    $("#btn_shmx_search").click(function () {
        xsmxSearch();
    });
});

function xsmxSearch() {
    $('#grid_shmx').datagrid('load',
        {
            xsdh:$('#shmx_xsdh').val(),
            sbgsId:$('#toolbar_shmx [name="shmx.gs.id"]').val(),
            khId:$('#toolbar_shmx [name="shmx.kh.id"]').val(),
            gysId:$('#toolbar_shmx [name="shmx.gys.id"]').val(),
            cght:$("#shmx_cght").val(),
            fhrqStart:$('#shmx_shsj_start').datebox('getValue'),
            fhrqEnd:$('#shmx_shsj_end').datebox('getValue')
        }
    );
}